<%@ page import="com.oval.util.JspHelper" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oval.foundation.util.*" %>
<%@ page import="com.oval.foundation.engine.*" %>
<%@ page contentType = "text/html;charset=UTF-8" %>
<%
  String enid = request.getParameter("edit_enid");
  String cnid = request.getParameter("edit_cnid");
  String jpid = request.getParameter("edit_jpid");
  String messagecode = request.getParameter("edit_messagecode");
  String messagetype = request.getParameter("edit_messagetype");
  String messagedesccn = OvalEncode.convertEncode(request.getParameter("edit_messagedesccn"),"iso-8859-1","utf-8");
  String messagedescen = request.getParameter("edit_messagedescen");
  String messagedescjp = OvalEncode.convertEncode(request.getParameter("edit_messagedescjp"),"iso-8859-1","utf-8");
  String messagename = request.getParameter("edit_messagename");
  String module = request.getParameter("edit_module");
  
  //the following is for label editing from client page by ps !  // by andyyang 2003/01/20
  boolean isForPageEdit = false;
  String editforps = "";
  if(request.getParameter("editforps")!=null)
    editforps = request.getParameter("editforps");    
  if(editforps.equalsIgnoreCase("y"))
  {    
    isForPageEdit = true;
    messagename=(String)request.getParameter("messagename");    
    if(messagename!=null)
    {
      OvalSearchAPI osa = new OvalSearchAPI();      
      String whereclause = "";
      if(messagename != null && messagename.length() != 0)
    	whereclause += " and messagename like '" + messagename + "'";
      whereclause += " order by module asc, messagecode asc";
      Vector messages = osa.getSearchResults("ovovalmessage",whereclause,null,null);
      if(messages==null)
        messages = new Vector();
      
      if(messages.size()==3)
      {
        HashMap cnMessage=new HashMap();
        HashMap enMessage=new HashMap();
        HashMap jpMessage=new HashMap();
        for(int ii=0;ii<messages.size();ii++)
        {
          HashMap tempMessage=(HashMap)messages.get(ii);
          if((String)tempMessage.get("languagecode")!=null && ((String)tempMessage.get("languagecode")).equalsIgnoreCase("cn"))
            cnMessage = tempMessage;
          else if((String)tempMessage.get("languagecode")!=null && ((String)tempMessage.get("languagecode")).equalsIgnoreCase("en"))
            enMessage = tempMessage;
          else if((String)tempMessage.get("languagecode")!=null && ((String)tempMessage.get("languagecode")).equalsIgnoreCase("jp"))
            jpMessage = tempMessage;
        }
        if(cnMessage!=null || enMessage!=null || jpMessage!=null)
        {
          enid=((Integer)enMessage.get("messageid")).toString();
          cnid=((Integer)cnMessage.get("messageid")).toString();
          jpid=((Integer)jpMessage.get("messageid")).toString();
	  messagecode=(String)cnMessage.get("messagecode");
	  if(messagecode==null)
	    messagecode=(String)enMessage.get("messagecode");
	  messagedesccn=(String)cnMessage.get("messagedesc");
	  messagedescen=(String)enMessage.get("messagedesc");	  
	  messagedescjp=(String)jpMessage.get("messagedesc");
        }      
      } 
    }
  }
%>
<html>
<head>
<title>e-manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/chinese/csscontent.css" type="text/css"> 
<script language="JavaScript" src="../css/chinese/script.js"></script>
<script language="JavaScript">

<%--what to do if press DONE Button--%> 

function page_done()
{
<%if(isForPageEdit){%>
if(isEmpty(frm.messagecode.value) || isEmpty(frm.messagename.value) || isEmpty(frm.messagedescen.value) || isEmpty(frm.messagedesccn.value) || isEmpty(frm.messagedescjp.value))
  {
    alert("please input every data!");  
    return;
  }
  <%--[SCRIPT]  alert(frm.messagename.value);  [SCRIPT]--%>
  <%--[SCRIPT]  alert(frm.oldmessagename.value);  [SCRIPT]--%>
  <%--[SCRIPT]  return;  [SCRIPT]--%>
if(frm.messagename.value != frm.oldmessagename.value)
  {
    frm.edit_enid.value = "";
    frm.edit_cnid.value = "";
    frm.edit_jpid.value = "";
  }
if(frm.edit_enid.value=="" || frm.edit_cnid.value=="" || frm.edit_jpid.value=="")
  {
    alert("Sorry! Can not insert!");  
    return;
  }
  frm.editforps.value="Y";
<%}else{%>  
  if(!isEmpty(frm.messagetype.value) && frm.messagetype.value != "P" && frm.messagetype.value != "J" && frm.messagetype.value != "U" && frm.messagetype.value != "A" && frm.messagetype.value != "C" && frm.messagetype.value != "T")
  {
    alert("Message Type must be P/J/U/A/C/T");
    return;
  }  
  if(isEmpty(frm.messagecode.value) || isEmpty(frm.messagetype.value) || isEmpty(frm.messagename.value) || isEmpty(frm.messagedescen.value) || isEmpty(frm.messagedesccn.value) || isEmpty(frm.messagedescjp.value))
  {
    alert("except module, please input every data!");  
    return;
  }
<%}%>  
  frm.actionname.value = "edit";
  document.frm.submit();
}
function page_search()
{
  frm.actionname.value = "search";
  if(frm.messagename.value=='')
  {
    alert("the messagename can not empty!");
    frm.messagename.focus();
    return;
  }    
  self.location.href = "MessageEdit.jsp?messagename="+frm.messagename.value+"&editforps=<%=JspHelper.filterNull(editforps)%>";
}

<%--Display The Page--%>  

</script>
</head>
<body>
<form name="frm" action="MessageAction.jsp">
  <input type="hidden" name="actionname">
  <input type="hidden" name="edit_enid" value="<%=JspHelper.filterNull( enid )%>">
  <input type="hidden" name="edit_cnid" value="<%=JspHelper.filterNull( cnid )%>">
  <input type="hidden" name="edit_jpid" value="<%=JspHelper.filterNull( jpid )%>">
  <input type="hidden" name="editforps"> 
  <input type="hidden" name="oldmessagename" value="<%=JspHelper.filterNull( messagename )%>">
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#999999">
  <tr> 
    <td class="td_title_bg">
      Message Code
    </td>
    <%if(!isForPageEdit){%>
    <td class="td_title_bg">
      Message Type
    </td>
    <%}%>
    <td class="td_title_bg">
      Message Desc(CN)
    </td>
    <td class="td_title_bg">
      Message Desc(EN)
    </td>    
    <td class="td_title_bg">
      Message Desc(JP)
    </td>  
     <td class="td_title_bg">
      Message Name
    </td>
    <%if(!isForPageEdit){%>
    <td class="td_title_bg">
      Module
    </td>
    <%}%>
  </tr>
     <tr class="td_bg_row">      
       <td class="text">
         <div align="left">
           <input type="text" name="messagecode" value="<%=JspHelper.filterNull( messagecode )%>">
         </div>
       </td>
       <%if(!isForPageEdit){%>
       <td class="text">
         <div align="left">
           <input type="text" name="messagetype" value="<%=JspHelper.filterNull( messagetype )%>">
         </div>
       </td>
       <%}%>
       <td class="text">
         <div align="left">
           <input type="text" name="messagedesccn" value="<%=JspHelper.filterNull( messagedesccn )%>">
         </div>
       </td>
       <td class="text">
         <div align="left">
           <input type="text" name="messagedescen" value="<%=JspHelper.filterNull( messagedescen )%>">
         </div>
       </td>       
       <td class="text">
         <div align="left">
           <input type="text" name="messagedescjp" value="<%=JspHelper.filterNull( messagedescjp )%>">
         </div>
       </td>       
       <td class="text">
         <div align="left">
           <input type="text" name="messagename" value="<%=JspHelper.filterNull( messagename )%>">
         </div>
       </td>
       <%if(!isForPageEdit){%>
       <td class="text">
         <div align="left">
           <input type="text" name="module" value="<%=JspHelper.filterNull( module )%>">
         </div>
       </td>
       <%}%>
     </tr>
  <tr> 
    <td class="td_title_bg" colspan="10">
         <div align="center">
           <input type="button" name="DONE" value="DONE" onclick="javascript:page_done()">
           <%if(isForPageEdit){%>
           <input type="button" name="Search" value="Search" onclick="javascript:page_search()">
           <input type="button" name="BACK" value="CANCEL" onclick="javascript:window.close()">           
           <%}else{%>
           <input type="button" name="BACK" value="BACK" onclick="javascript:history.go(-1)">
           <%}%>
         </div>
    </td>
  </tr>
</table>
</form>
</body>
</html>

